package com.sgb.kjwl.view.widget;

import android.content.Context;
import android.graphics.Color;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.swgk.core.view.entity.TalentEntity;
import com.swgk.core.dialog.BasePopWindow;
import com.swgk.core.dialog.PopViewHolder;


public class TalentPopWindow extends BasePopWindow {

    private ImageView ivCancel;
    Context context;
    RoundImageView rivHead;
    TalentEntity talentEntity;
    TextView titleView;
    TextView age;
    TextView experience;
    TextView position;
    TextView goodWork;
    TextView person;

    public TalentPopWindow(Context context) {
        super(context, DIR_DOWN_UP);
        this.context = context;
    }

    @Override
    protected int popLayout() {
        return R.layout.popwindow_talent;
    }

    @Override
    protected void initView(PopViewHolder holder) {
        holder.setBinding(BR.viewModel, talentEntity);
        ivCancel = holder.getPop().findViewById(R.id.iv_cancel);
        ivCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        rivHead = holder.getPop().findViewById(R.id.logo_view);
        titleView = holder.getPop().findViewById(R.id.title_view);
        age = holder.getPop().findViewById(R.id.tv_age);
        experience = holder.getPop().findViewById(R.id.tv_experience);
        position = holder.getPop().findViewById(R.id.tv_position);
        goodWork = holder.getPop().findViewById(R.id.tv_good_work);
        person = holder.getPop().findViewById(R.id.tv_person);

    }


    public TalentPopWindow setData(TalentEntity talentEntity) {
        this.talentEntity = talentEntity;
        if (talentEntity != null) {
            Glide.with(context).load(talentEntity.getHeadImg()).into(rivHead);
            titleView.setText(talentEntity.getName());
            age.setText(talentEntity.getAge() + "岁");
            experience.setText(talentEntity.getExperience() + "年");
            position.setText(talentEntity.getPosition());

            SpannableString spannableString = new SpannableString("擅长业务：" + talentEntity.getBusiness());
//设置颜色
            spannableString.setSpan(new ForegroundColorSpan(Color.parseColor("#666666")), 0, 4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            goodWork.setText(spannableString, TextView.BufferType.SPANNABLE);

            SpannableString spannableString1 = new SpannableString("个人简介：" + talentEntity.getProfile());
//设置颜色
            spannableString1.setSpan(new ForegroundColorSpan(Color.parseColor("#666666")), 0, 4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            person.setText(spannableString1, TextView.BufferType.SPANNABLE);
        }
        return this;
    }
}
